console.log(location.search);
let obj = new URLSearchParams(location.search);
console.log(obj.get("pid"));
let pid = obj.get("pid");

axios.get(productDetailAPI,{
    params: {id:pid},
}).then((res)=>{
    let {data}=res;
    console.log(data);

    let pObj = data.data;
    let html=`
        <div class="product1">
        <div class="product2"><img src="${pObj.pimg}" alt=""></div>
        <div class="product3">
            <div class="product4">${pObj.pname}</div>
            <div class="product5">${pObj.pprice}</div>
            <div class="product6">
                <div class="product7">数量</div>
                <div class="product8">
                    <button class="product9" onclick = "subBtn(${pid},this)">-</button>
                    <input type="text" class="product10" value="1">
                    <button class="product11" onclick = "addBtn(${pid},this)">+</button>
                </div>
                <div class="product12" onclick = "cartAdd()">加入购物车</div>
            </div>
        </div>
    </div>
    `


    let productDiv = document.querySelector(".product1");
    productDiv.innerHTML=html;

    // let cartAdd = document.querySelector(".product12")
    // console.log(cartAdd);
  

    
})
function subBtn(pid,btn){
    console.log(111);
    let ipt = btn.nextElementSibling;
    console.log(ipt);
    let pnum = ipt.value
    console.log(pnum);
    if(pnum == 1){
        pnum=1;
    }else{
        pnum--;
    }
    ipt.value = pnum;
}
function addBtn(pid,btn){
    console.log(111);
    console.log(this);
    console.log(btn);
    let ipt = btn.previousElementSibling;
    console.log(ipt);
    let pnum = ipt.value
    console.log(pnum);
    pnum++;
    console.log(pnum);
    ipt.value = pnum;
    

}

async function cartAdd(){
    console.log(111);
    let uid = localStorage.getItem("uid");
    console.log(uid);
    let pnumIpt = document.querySelector(".product10");
    console.log(pnumIpt);
    pnum = pnumIpt.value;
    let params = {uid,pid,pnum};
    console.log(params);
    let {data}= await axios.get(CartAddAPI,{params});
    console.log(data);

}
// cartAdd.onclick = async function(){
   
// }